package com.project.common.fundamental.response.body;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.project.common.exception.ErrorCode;

import java.util.Date;

public class ErrorBody implements ResponseBody {
    private int errorCode;
    private String message;
    private Throwable exception;
    private Date timestamp;

    public ErrorBody(ErrorCode errorCode) {
        this(errorCode.getCode(), errorCode.getMessage());
    }

    public ErrorBody(int errorCode, String message) {
        this(errorCode, message, null);
    }

    public ErrorBody(ErrorCode errorCode, Throwable exception) {
        this(errorCode.getCode(), errorCode.getMessage(), exception);
    }

    @JsonCreator
    public ErrorBody(
        @JsonProperty("errorCode") int errorCode,
        @JsonProperty("message") String message,
        @JsonProperty("exception") Throwable exception) {
        this.errorCode = errorCode;
        this.message = message;
        this.exception = exception;
        this.timestamp = new Date(System.currentTimeMillis());
    }

    public int getErrorCode() {
        return errorCode;
    }

    public String getMessage() {
        return message;
    }

    public Throwable getException() {
        return exception;
    }

    public Date getTimestamp() {
        return timestamp;
    }
}
